//
//  Global.h
//  CommonProject
//
//  Created by 郝旭珊 on 2017/12/19.
//  Copyright © 2017年 郝旭珊. All rights reserved.
//

#ifndef Global_h
#define Global_h


#define OPENAPIHOST @"http://103.7.212.15:85/sof/"
#define OPENAPIHOST_IMAGE @"" OPENAPIHOST"upload/"
#define USERDEFAULTS [NSUserDefaults standardUserDefaults]


#define NONETWORKMESSAGE @"网络环境不佳"
#define ERRORMESSAGE @"服务器开小差了"
#define LOADING @"加载中..."


//.h文件的替换
#define singleton_h(objname) +(instancetype)share##objname;
//.m文件的替换
#if __has_feature(objc_arc)
#define singleton_m(objname)                                                    \
static id instance;                                                         \
+(instancetype)share##objname                                               \
{                                                                           \
static dispatch_once_t onceToken;                                       \
dispatch_once(&onceToken, ^{ instance = [[self alloc] init]; });        \
return instance;                                                        \
}                                                                           \
\
+(instancetype)allocWithZone : (struct _NSZone*)zone                        \
{                                                                           \
static dispatch_once_t onceToken;                                       \
dispatch_once(&onceToken, ^{ instance = [super allocWithZone:zone]; }); \
return instance;                                                        \
}                                                                           \
-(id)copyWithZone:(struct _NSZone*) zone                                     \
{                                                                           \
return instance;                                                        \
}
#else
//非arc
#define singleton_m(objname)                                                    \
static id instance;                                                         \
+(instancetype)share##objname                                               \
{                                                                           \
static dispatch_once_t onceToken;                                       \
dispatch_once(&onceToken, ^{ instance = [[self alloc] init]; });        \
return instance;                                                        \
}                                                                           \
\
+(instancetype)allocWithZone : (struct _NSZone*)zone                        \
{                                                                           \
static dispatch_once_t onceToken;                                       \
dispatch_once(&onceToken, ^{ instance = [super allocWithZone:zone]; }); \
return instance;                                                        \
}                                                                           \
-(id)copyWithZone(struct _NSZone*) zone                                     \
{                                                                           \
return instance;                                                        \
}                                                                           \
-(oneway void)release{} - (instancetype)autorelease                         \
{                                                                           \
return instance;                                                        \
}                                                                           \
-(instancetype)retain                                                       \
{                                                                           \
return instance;                                                        \
}                                                                           \
-(NSUInteger)retainCount                                                    \
{                                                                           \
return 1;                                                               \
}
#endif

#endif /* Global_h */
